package id.net.iconpln.bb.client.view;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;

public class PageRekapBbSemuaKontrakTahunan extends LayoutContainer{
	private ContentPanel cp;
	private Grid laypanel;
	private Grid grid;
	private GroupingStore store;
	Window window;
	FormData formData;
	
	final NumberFormat currency = NumberFormat.getCurrencyFormat();  
    final NumberFormat number = NumberFormat.getFormat("0.00");  
    final NumberCellRenderer<Grid> numberRenderer = new NumberCellRenderer<Grid>(currency); 
	
	 @Override
	  protected void onRender(Element parent, int pos) {
	    super.onRender(parent, pos); 
	    setLayout(new FitLayout());
	    final ToolBar toolBar = new ToolBar();
	    ToolBar toolBar1 = new ToolBar();
	    formData = new FormData("-20");
		
	    
	    Button btconfigure = new Button("Konfigurasi", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {
		    	  
		    	  	FormPanel simple = new FormPanel();  
				    simple.setHeaderVisible(false);
				    simple.setFrame(true);
				    simple.setAutoHeight(true);
				    simple.setWidth(350); 
				    
				    final SimpleComboBox<String> jeniskontrak = new SimpleComboBox<String>();  
				    jeniskontrak.setFieldLabel("Jenis Kontrak"); 			    
				    simple.add(jeniskontrak, formData);
				    
				    final SimpleComboBox<String> tahun = new SimpleComboBox<String>();  
				    tahun.setFieldLabel("Tahun"); 			    
				    simple.add(tahun, formData);
				    
				    simple.setButtonAlign(HorizontalAlignment.LEFT);  
				    simple.addButton(new Button("Cancel", new SelectionListener<ButtonEvent>() {  
				      @Override  
				      public void componentSelected(ButtonEvent ce) {  
				    	window.close();
				      }  
				    }));  
				    simple.addButton(new Button("Simpan", new SelectionListener<ButtonEvent>() {  
				      @Override  
				      public void componentSelected(ButtonEvent ce) {
				    	  
				    	  
					      }  
				    }));  
				    
				    simple.setButtonAlign(HorizontalAlignment.CENTER); 
		    	  
		    	  
		    	  	window = new Window();  
				    window.setHeading("Parameter Laporan"); 
				    window.setLayout(new FitLayout());
				    window.setAutoHeight(true);
				    window.setWidth(600);
				    window.setScrollMode(Scroll.AUTO);
				    window.add(simple);
				    
		        	window.show();
		    	  
		    	  
		      }  
		    });  
		    
	    btconfigure.setIcon(IconHelper.createStyle("icon-reza-configure"));
	    
	    cp = new ContentPanel();
		cp.setLayoutOnChange(true); 
		cp.setCollapsible(false);
		cp.setFrame(false);
		cp.setLayout(new FitLayout());
		cp.setBorders(false);
		cp.setHeaderVisible(false);
		
		final SimpleComboBox<String> tahun = new SimpleComboBox<String>();
		tahun.setEmptyText("Pilih Tahun.."); 
		final SimpleComboBox<String> tahun1 = new SimpleComboBox<String>();
		tahun1.setEmptyText("Pilih Tahun.."); 
	    final SimpleComboBox<String> jeniskontrak = new SimpleComboBox<String>();
	    jeniskontrak.setEmptyText("Pilih Jenis Kontrak.."); 

	    Button btcetak = new Button("Cetak", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {
		    	  
		      }  
		    });  
	    btcetak.setIcon(IconHelper.createStyle("icon-printer"));
	    
    	toolBar.add(new LabelToolItem("<b>Rencana dan Realisasi Kontrak &nbsp;"));
    	toolBar.add(jeniskontrak);
    	toolBar.add(new LabelToolItem("<b>&nbsp;"));
    	toolBar.add(tahun);
    	toolBar.add(new LabelToolItem("<b>&nbsp; s.d &nbsp;"));
    	toolBar.add(tahun1);
    	toolBar.add(new SeparatorToolItem());
		toolBar.add(btcetak);
    	
    	
    	
    	
    	
//    	toolBar.setAlignment(HorizontalAlignment.CENTER);
//    	toolBar1.add(btconfigure);
//		toolBar1.add(new SeparatorToolItem());
    	cp.setTopComponent(toolBar);
//    	cp.setBottomComponent(toolBar1);
    	cp.syncSize();

		laypanel = task();
		cp.add(laypanel);  
	  
			
		add(cp, new FitData(5));
	}
	 
	private Grid task(){
		   	
			List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  
		    
		   	store = new GroupingStore();  
		    getDataGrid();
		   
		    ColumnConfig column = new ColumnConfig();  
		    
		    column = new ColumnConfig();  
		    column.setId("name");  
		    column.setHeader("<center>Pemasok");  
		    column.setWidth(150);  
		    configs.add(column);  
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Kontrak");  
		    column.setWidth(330);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Jumlah <br> (Ton)");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Batas Kontrak");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Perpanjangan Waktu");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Posisi");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>v_tahun");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Realisasi <br>(Ton)");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Ton");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>%");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    ColumnModel cm = new ColumnModel(configs);
		    cm.addHeaderGroup(0, 6, new HeaderGroupConfig("Tahun", 1, 1));//dinamis column model
		    cm.addHeaderGroup(0, 8, new HeaderGroupConfig("Deviasi", 1, 2));
		    
		    grid = new Grid(store, cm);  
		    grid.setBorders(false);
		      
		    
		return grid;
	}
	  
	
	private void getDataGrid() {
	
	}
	
	
}